<?php

/**
 * Created by PhpStorm.
 * User: wukent
 * Date: 2017/9/25
 * Time: 下午5:59
 */
class PaymentAction extends ApiAction
{

    public function index(){
        vendor('alipaysdk.aop.AopClient');
        vendor('alipaysdk.aop.request.AlipayTradeAppPayRequest');

//        require "aop/AopClient.php";
//        require "aop/request/AlipayTradeAppPayRequest.php";

        $out_trade_no = 'xx26'.time();


        //$total_price = $this->post('total_price');
        $total_price = 0.1;


        $aop = new AopClient;
        $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
        $aop->appId = "2017080408031021";
        $aop->rsaPrivateKey = 'MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCS7cOhZCZTKBp+0+os+FEr1WUUDSzH8HfpXvu2wMlWy8v1Mpuuu4HraksS/LksClw7B6ZHXsciMyGdnGPJIERrBCOCPtvtt9BxTDHWUIbBwAxs8o305Q01xlg1YAljKpcr4eyhhUo7t6tkwcMOx+KQChKve/ALRJAOFxA+sjEg20pzKgx1HDk145sXxdx0/9SQP5yTd0fHGWdFQFMWzKW629EXVhJuwmWkSYVjT54RIquSAqI1CTNpGm4cHAiOK8YHsE9VsQPBNcpx4nltw3O/QA8gzhn4sH96yJpIeMYLq0cR4PKIhgLwNg0v8Olqbq8P3TLMyuJZqvh0Q67DQvxFAgMBAAECggEBAI1t6N21dV6eP8LNYaCf9iJnasB+XhinVAWDtHAZ6rRtv4nqiQkM3OYqjtFcCzJlVppLprcUeEJnTXhVTYgQU0tf1H5O24xbX31vhplxMgXWQx+r6xFMWgblQYs/Qkn+eT14Xzqq/uW0ynpWONhFd8SGra3Vcx6lhLTLZouzIq8oY900PAOl14xCGsX7Zfmrf8zaG5U9/MJMqFR6CMEmntXu7wZNW9XgEqrHh+kuA4sQ+bZwLLzaxy2I6w2gJWNgb+vczU2w3Fg0D9fi+f+EPViG9YIaABdaepLOoldDNKwU0OdU28Q3xuQIdh2wQ1/WNo+4F9anN7gqup73ZvYzVAECgYEA/fpyetqnLVaRuI0mhwNnJN5hqPM6w3igr8AxcpANALxTUKClyK0SzVJpb6W2Oh54B6gYKrKxrkEv0l9YpSLDe1WuouDTNUu7B6V8c0sEtGclyKP2btc/rp5uf9/aYhxKEwlJ1/iE2R3VjLzLFq/4u65vlOo6nLxl9Ly3NhFvW8ECgYEAlBksVtOai9sPbwgrrbod0WAc/wo1+7oBRM0i4vLC03s9LhA2X+q0k3y8aV3eja1Fcd8x5HTSgyh3y3M3wwvOzUAuutgu6UEQTySw4TrChqyKvak9Z18UpBIPUPELjZLqEfo//RBjSph6mDivfDWsg5jRfvvXU9HzJMJVwr1wkYUCgYEAn2aMaybIPeBTXOzZ/WrZVX5s9MiTXRNcZnHNlwVp48hO0g/BfQ2C+3J50iTDFf8Bfmy1njbA5YjsJrDIxfvnjITeMkPAy3ZYUBhA32t57G/AewjNJgvaYBH3cDJisajnpMLzoaTMXCgpW0cyf266QbDdPy0y1CQ6KTw4EKsopQECgYAEB3dMWW9v9KLD244MqO6cvqerTKTRV2snawlS8VXZmRW+BhTkoScOiCs8FqCybA9inLbnx0He7Z/suhK/TLfwn5ll3fHQyMNf09i4F/go39LafBs+j7ipChC+nAA7ds7FdHB/Ow3ofqN/NrOXhoJOBj9U3BcsoZ6i1mKs7Kh+XQKBgQDeNjFql40jwTqUcdQ7crM2CcgwUxdKmkSBj9S/2nfhtQ/xxUtJbgD8oMRGY8wP4R3t36HhNBH3SY3ktDhX4wP2Nze5I2fUeCAil/qc+7AOcZGjEYrEYOTljOrVIVzEfSaycvG7QXjQIal1wOhPqLXUNFBd+LowWf6nzrdmf0YBYw==' ;
//$aop->format = "json";
        $aop->charset = "utf-8";
        $aop->signType = "RSA2";
//$aop->alipayrsaPublicKey = '请填写支付宝公钥，一行字符串';
        $aop->alipayrsaPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApV/jU0SgPXt8uryI2TxpAwBP+gbf6IZRrpjWoa4LYoVQxjXqXumm17d0vSHrYblQAlehQiQnm6lW2PXeIa7+pAtghUn9qdAg6eM/46r8nQ5iOVnQUtcHwxUChdm5C6OjzeHpFN0qxpoYZKpUs2COOwE5IiQkaTiJkP0I6TC1D5qoap2StCpcKJFPnXvjybLQjesbznTx5KPrAh+G4cUTCHDPiHZSd+iV7QPRnkN5gtQjpO187+hD80VzhwHVKNHpWALzOQ728W8wJcFvaIGyy1Oku0WPDNsHPEcCtp4D+L2wN/Zy2BjwW0JjdXYOi8QpXMW818JDKHBsFsZKMNlj0QIDAQAB';
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
        $request = new AlipayTradeAppPayRequest();
//SDK已经封装掉了公共参数，这里只需要传入业务参数
        $bizcontent = "{\"subject\": \"食安购\","
            . "\"out_trade_no\": \"{$out_trade_no}\","
            . "\"timeout_express\": \"30m\","
            . "\"total_amount\": \"{$total_price}\","
            . "\"product_code\":\"QUICK_MSECURITY_PAY\""
            . "}";

        $request->setNotifyUrl("http://test.shiangou.com.cn/app/alipay/notifycheck.php");
        $request->setBizContent($bizcontent);
//这里和普通的接口调用不同，使用的是sdkExecute
        $response = $aop->sdkExecute($request);
//htmlspecialchars是为了输出到页面时防止被浏览器将关键参数html转义，实际打印到日志以及http传输不会有这个问题

//var_dump($response);
//exit("doc");
//$rinfo =  htmlspecialchars($response);//就是orderString 可以直接给客户端请求，无需再做处理。

        $this->rest($response,1);



    }


    public function notifycheck(){

        //require ('/aop/AopClient.php');
        vendor('alipaysdk.aop.AopClient');
        $aop = new AopClient;
//公钥
        $aop->alipayrsaPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApV/jU0SgPXt8uryI2TxpAwBP+gbf6IZRrpjWoa4LYoVQxjXqXumm17d0vSHrYblQAlehQiQnm6lW2PXeIa7+pAtghUn9qdAg6eM/46r8nQ5iOVnQUtcHwxUChdm5C6OjzeHpFN0qxpoYZKpUs2COOwE5IiQkaTiJkP0I6TC1D5qoap2StCpcKJFPnXvjybLQjesbznTx5KPrAh+G4cUTCHDPiHZSd+iV7QPRnkN5gtQjpO187+hD80VzhwHVKNHpWALzOQ728W8wJcFvaIGyy1Oku0WPDNsHPEcCtp4D+L2wN/Zy2BjwW0JjdXYOi8QpXMW818JDKHBsFsZKMNlj0QIDAQAB';
        $flag = $aop->rsaCheckV1($_POST, NULL, "RSA");

//if ($flag){
//    $pay_name = $_POST['pay_name']; 			//支付方式
//    $sql = "update ecs_order_info set pay_status='2',pay_name='支付宝',pay_time=";
//    $res = mysqli_query($mysql,$sql);
//    echo 'success';
//}

        echo 'success';

    }



}